package com.tarena.vehicle.management.controller;

import com.tarena.vehicle.common.pojo.vo.PageData;
import com.tarena.vehicle.common.web.JsonResult;
import com.tarena.vehicle.management.pojo.param.VehicleMaintenanceAddNewParam;
import com.tarena.vehicle.management.pojo.param.VehicleMaintenanceUpdateParam;
import com.tarena.vehicle.management.pojo.query.VehicleMaintenanceQuery;
import com.tarena.vehicle.management.pojo.vo.VehicleMaintenanceListItemVO;
import com.tarena.vehicle.management.pojo.vo.VehicleMaintenanceStandardVO;
import com.tarena.vehicle.management.service.IVehicleMaintenanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/VehicleMaintenance")
@Api(tags ="车辆维修信息管理" )
public class VehicleMaintenanceController {

    @Autowired
    private IVehicleMaintenanceService vehicleMaintenanceService;

    @PostMapping("/add-new")
    @ApiOperation("新增车辆维修记录")
    public JsonResult addNewVehicleMaintenance(VehicleMaintenanceAddNewParam param){
        vehicleMaintenanceService.addNew(param);
        return JsonResult.ok("新增成功");
    }

    @GetMapping("/get-vehicle-vaintenance/{id}")
    @ApiOperation("根据ID查询车辆维修记录")
    public JsonResult<VehicleMaintenanceStandardVO> getVehicleMaintenanceById(@PathVariable Integer id){
        VehicleMaintenanceStandardVO vo=vehicleMaintenanceService.getVehicleMaintenanceById(id);
        return JsonResult.ok(vo);
    }

    @GetMapping("/update-status-done/{id}")
    @ApiOperation("修改车辆维修状态为已完成")
    public JsonResult updateStatusDone(@PathVariable Integer id){
        vehicleMaintenanceService.updateStatusDone(id);
        return JsonResult.ok("修改状态完成");
    }

    @PostMapping("/update-vehicle-vaintenance")
    @ApiOperation("修改车辆维修信息")
    public JsonResult update(VehicleMaintenanceUpdateParam vehicleMaintenanceUpdateParam){
        vehicleMaintenanceService.update(vehicleMaintenanceUpdateParam);
        return JsonResult.ok("修改成功");
    }

    @GetMapping("/delete-vehicle-vaintenance/{id}")
    @ApiOperation("删除车辆维修信息")
    public JsonResult delete(@PathVariable Integer id){
        vehicleMaintenanceService.deleteById(id);
        return JsonResult.ok("删除成功");
    }

    @PostMapping("/get-vehicle-vaintenance/all")
    @ApiOperation("查询全部车辆维修记录")
    public JsonResult<PageData<VehicleMaintenanceListItemVO>>  getVehicleMaintenanceList(VehicleMaintenanceQuery vehicleMaintenanceQuery,Integer pageNum,Integer pageSize){
        PageData<VehicleMaintenanceListItemVO> pageData= vehicleMaintenanceService.getVehicleMaintenanceList(vehicleMaintenanceQuery,pageNum,pageSize);
        return JsonResult.ok(pageData);
    }

}
